#### SENSITIVITY TEST: Interacting results with gender ####
mod_ced_sex_interact <-  lm(percent ~
                              scale(last_algorithm) *
                              female +
                              scale(first_algorithm) +
                              scale(percent_freq) +
                              scale(fprop) +
                              white +
                              incumbent +
                              lchars +
                              fchars +
                              totvotes1000 +
                              office +
                              seats_comps +
                              factor(year) +
                              factor(co_name),
                            data = ced)

cedr2 <- get_r2(mod_ced_sex_interact)
mod_ced_sex_interact <- get_clusters(mod_ced_sex_interact)

mod_primary_sex_interact <- lm(ppct ~
                                 scale(last_algorithm) *
                                 female +
                                 scale(first_algorithm) +
                                 scale(percent_freq) +
                                 scale(fprop) +
                                 white +
                                 incumbent +
                                 lchars +
                                 fchars +
                                 race +
                                 num_prim_opps +
                                 party +
                                 factor(year) +
                                 factor(state),
                               data = primary)

primaryr2 <- get_r2(mod_primary_sex_interact)
mod_primary_sex_interact <- get_clusters(mod_primary_sex_interact)


mod_general_sex_interact <- lm(gpct ~
                                 scale(last_algorithm) *
                                 female +
                                 scale(first_algorithm) +
                                 scale(percent_freq) +
                                 scale(fprop) +
                                 white +
                                 incumbent +
                                 lchars +
                                 fchars +
                                 race +
                                 factor(party) +
                                 factor(year) +
                                 factor(state),
                               data = general)

generalr2 <- get_r2(mod_general_sex_interact)
mod_general_sex_interact <- get_clusters(mod_general_sex_interact)

stargazer(mod_general_sex_interact, mod_primary_sex_interact, mod_ced_sex_interact,
          type = "latex",
          title = "Relationship Between Name Fluency and Vote Share Including Interaction with Gender",
          style = "ajps",
          ci = F,
          model.names = F,
          star.cutoffs = c(.05, .01, .001),
          star.char = c("*", "**", "***"),
          notes = "Standard errors are clustered by election",
          keep = c("last_algorithm",
                   "first_algorithm",
                   "percent_freq",
                   "fprop",
                   "female",
                   "last_algorithm*female"),
          covariate.labels = c("Surname Pronounceability",
                               "Female",
                               "First Name Pronounceability",
                               "Last Name Commonality",
                               "First Name Commonality",
                               "Surname Pronounceability * Female"),
          add.lines=list(c("Year FE", "\\checkmark", "\\checkmark", "\\checkmark"),
                         c("County FE", "", "", "\\checkmark"),
                         c("State FE", "\\checkmark", "\\checkmark", ""),
                         c("Controls", "\\checkmark", "\\checkmark", "\\checkmark"),
                         c("N", get_n(mod_general_sex_interact), get_n(mod_primary_sex_interact), get_n(mod_ced_sex_interact)),
                         c("Adj. R-squared", generalr2, primaryr2, cedr2)),
          align = F,
          keep.stat = c("n", "adj.rsq"),
          column.labels = c("General Elections", "Primary Elections", "Local Elections"),
          out = "tables/reg-gender-interaction.tex",
          label = "tab:reg-gender-interact")

